package com.yuejian_06.yuejian_06.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.activity.AcInfoActivity;
import com.yuejian_06.yuejian_06.bean.ActivityBean;
import com.yuejian_06.yuejian_06.bean.PostListBean;

import java.util.List;

/**
 * Created by __ZL__ on 2017/10/13.
 */

public class ActivityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public ActivityAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.activitylistcardview,parent,false);
        return new ActivityAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder,int position) {
        final ActivityBean entity =(ActivityBean) mDataList.get(position);
        if (null == entity)
            return;
        ActivityAdapter.ViewHolder viewHolder = (ActivityAdapter.ViewHolder) holder;
        viewHolder.activity_name.setText(entity.getActivity_name());
        //String p = String.valueOf(entity.getPrice());
        viewHolder.activity_good.setText(entity.getActivity_good());
        if (!"".equals(entity.getActivity_pic()))
            Picasso.with(mContext).load("http://10.0.2.2/yuejian/Public/acpics/"+entity.getActivity_pic()).into(viewHolder.activity_pic);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,AcInfoActivity.class);
                intent.putExtra("activity_id",entity.getActivity_id()+"");
//                intent.putExtra("foodname",entity.getFoodname()+"");
//                intent.putExtra("price",entity.getPrice()+"");
//                intent.putExtra("intro",entity.getIntro()+"");
//                intent.putExtra("pic",entity.getPic()+"");
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView activity_name,activity_good;
        private ImageView activity_pic;
        public ViewHolder(View itemView) {
            super(itemView);
            activity_name = (TextView) itemView.findViewById(R.id.activity_name);
            activity_good = (TextView) itemView.findViewById(R.id.activity_good);
            activity_pic = (ImageView) itemView.findViewById(R.id.activity_pic);
        }
    }
}
